#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using UnityEditor;
using UnityEngine;

namespace NeatlyEditor
{
    public class InspectorHelper
    {

        public static bool BeginFoldOut(string text, bool foldOut, bool endSpace = true)
        {

            text = "<b><size=12>" + text + "</size></b>";
            if (foldOut)
            {
                text = "+ " + text;
            }
            else
            {
                text = "~ " + text;
            }

            if (!GUILayout.Toggle(true, text, "dragtab"))
            {
                foldOut = !foldOut;
            }

            if (!foldOut && endSpace) GUILayout.Space(5f);

            return foldOut;
        }

        public static bool Toggle(string text, bool value, bool leftToggle)
        {
            GUI.backgroundColor = value ? Color.green : Color.white;
            value = leftToggle ? EditorGUILayout.ToggleLeft(text, value) : EditorGUILayout.Toggle(text, value);
            GUI.backgroundColor = Color.white;
            return value;
        }

        public static void BeginGroup(int padding = 0)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(padding);
            EditorGUILayout.BeginHorizontal("As TextArea", GUILayout.MinHeight(10f));
            GUILayout.BeginVertical();
            GUILayout.Space(5f);
        }

        public static void EndGroup(bool endSpace = true)
        {
            GUILayout.Space(5f);
            GUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(5f);
        }
    }
}
